<template>
  <div class="wrap">
    <van-index-bar>
      <template v-if="list.length">
        <div class="item" v-for="item in list" :key="item.biz_user_id">
          <div>
            <img :src="item.avatar?item.avatar:require('../assets/user2.png')" alt />
            <p>{{item.username}}</p>
          </div>
          <p class="exit" @click="followdele(item.biz_user_id)">取消关注</p>
        </div>
      </template>
      <div class="null" v-if="!list.length">
        <p>暂无关注商家</p>
      </div>
    </van-index-bar>
  </div>
</template>
<style lang="scss" scoped>
.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 8.64rem;
  margin: 0 auto;
  height: 1.986667rem;
  border-bottom: 1px solid #e5e5e5;
  div {
    display: flex;
    align-items: center;
    img {
      width: 1.013333rem;
      height: 1.013333rem;
      display: block;
      border-radius: 50%;
      margin-right: 0.186667rem;
      object-fit: cover;
    }
    p {
      color: #555;
      font-size: 0.4rem;
    }
  }
  .exit {
    width: 2.24rem;
    height: 0.6rem;
    color: #3fd9c9;
    border: 1px solid #3fd9c9;
    border-radius: 0.4rem;
    font-size: 0.4rem;
    text-align: center;
    line-height: 0.6rem;
  }
  span {
    padding: 2px 8px;
    border-radius: 0.266667rem;
    color: #fff;
    font-size: 0.32rem;
    background: #3fd9c9;
  }
}
.item:nth-last-of-type() {
  border: none;
}
</style>
<style>
.van-index-bar__index {
  font-size: 12px;
  line-height: 20px;
}
</style>
<script>
// https://segmentfault.com/a/1190000021057413?utm_source=tag-newest
import { followList, follow, followDele } from "@/utils/interface";
import { Toast, Dialog } from "vant";

export default {
  data() {
    return {
      FirstPin: [
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "J",
        "K",
        "L",
        "M",
        "N",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "W",
        "X",
        "Y",
        "Z"
      ],
      list: []
    };
  },
  methods: {
    // 取消关注
    followdele(id) {
      Dialog.confirm({
        title: "提示",
        message: "是否取消关注该商家"
      })
        .then(() => {
          followDele({ bizUserId: id }).then(res => {
            if (res.data.code == 200) {
              Toast.success("取消成功");
              this.getList();
            }
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    getList() {
      followList().then(res => {
        this.list = res.data.data;
      });
    }
  },
  mounted() {
    document.title = "我的关注";
    this.getList();
  }
};
</script>